import { RuleItem } from 'async-validator';
import { VNode } from 'vue';

export {};

export type EventsType = { [k in string]: <T = any, R = any>(arg: T) => R };
export type DataType = Record<string, unknown>;

export type FormPropsType<ModelType extends DataType = any> = {
	component?: FormProps;
	model?: ModelType;
	events?: EventsType;
	fields?: FormItemProps<ModelType>[];
	style?: CSSModuleClasses;
};
export type FormItemPropsType<ModelType extends DataType = any> = {
	model?: ModelType;
	field?: FormItemProps<ModelType>;
};

export type DynamicComponent = {
	name: string | JSX.Element | VNode;
	props: any;
	events?: any;
	style?: any;
	class?: any;
	// children?: DynamicComponent[]
};

export declare interface FormItemProps<Form = any, k = keyof Form> {
	item: {
		label?: string;
		labelWidth?: string | number | '';
		prop: k;
		required?: boolean | undefined;
		rules?: RuleItem | RuleItem[];
		error?: string;
		validateStatus?: string;
		for?: string;
		inlineMessage?: string | boolean | '';
		showMessage?: boolean | true;
		size?: 'large' | 'medium' | 'small' | 'mini';
	};
	value?: any;
	name?: string | JSX.Element | VNode;
	visible?: boolean | ((item?: FormItemProps) => boolean);
	component?: any;
	events?: any;
	slot?: any | { text: string };
	options?: Array<any>;
	remoteHandler?: (data: FormItemProps) => Promise<any>;
	// eslint-disable-next-line @typescript-eslint/ban-types
	remoteParams?: object;
	child?: FormItemProps;
	componentChildren?: DynamicComponent[];
}

export declare interface FormProps {
	labelPosition?: string;
	labelWidth: string | number | '';
	labelSuffix: string | '';
	inline?: boolean;
	inlineMessage?: boolean;
	statusIcon?: boolean;
	showMessage: boolean | true;
	size?: 'large' | 'medium' | 'small' | 'mini';
	disabled?: boolean;
	validateOnRuleChange: boolean | true;
	hideRequiredAsterisk: boolean | false;
}
